package br.com.websec.util;


import org.apache.log4j.Logger;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {

	private static final Logger logger = Logger.getLogger(HibernateUtil.class.getName());
	private static final SessionFactory session = buildSessionFactory();
	
	/*Metodo que estabelece a configuracao descrita no arquivo hibernate.cfg.xml*/
	private static SessionFactory buildSessionFactory() {

		try {
							
			Configuration configure = new Configuration();
			configure.configure("hibernate.cfg.xml");
			logger.info("Estabelecendo conexão.......");			
			return configure.buildSessionFactory();

		} catch (Throwable e) {
			e.printStackTrace();
			logger.error("Criacão inicial do objeto SessionFactory falhou. Erro: " + e.getMessage());
			throw new ExceptionInInitializerError();
		}

	}

	public static SessionFactory getSession() {

		return session;
	}

//	
//	public static void main(String args[]){
//		
//		HibernateUtil.getSession();
//	}
}